{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "# beautiful soup libraries\n",
    "from bs4 import BeautifulSoup\n",
    "from urllib.request import Request, urlopen\n",
    "import re \n",
    "import win32com.client\n",
    "import numpy as np\n",
    "\n",
    "# Get our Excel App\n",
    "ExcelApp = win32com.client.gencache.EnsureDispatch('Excel.Application')\n",
    "\n",
    "# Get our Worksheet\n",
    "WrkSht = ExcelApp.ActiveSheet\n",
    "\n",
    "# Define Range of URl\n",
    "Url_List = WrkSht.Range(\"A1:C1\").Value\n",
    "\n",
    "# Define a section initalizer, \n",
    "# this will make sure we dump the urls in the proper column.\n",
    "section_init = 1\n",
    "\n",
    "# Loop through each url in the url_list\n",
    "for url in Url_List[0]:\n",
    "    \n",
    "    # Request the URL, and initialize the list that will store the URLs\n",
    "    req = Request(url)\n",
    "    html_page = urlopen(req)\n",
    "    column_list =[]\n",
    "    \n",
    "    # Get the HTML content\n",
    "    soup = BeautifulSoup(html_page, 'html.parser')\n",
    "    \n",
    "    # Loop through each of HREF links and store them in the list.\n",
    "    for link in soup.findAll('a'):\n",
    "        row_list = []\n",
    "        row_list.append(link.get('href'))\n",
    "        column_list.append(row_list)\n",
    "\n",
    "    # Dump the urls in the proper sections.\n",
    "    StrCell = WrkSht.Cells(2, section_init)\n",
    "    EndCell = WrkSht.Cells(2 + len(column_list), section_init)    \n",
    "    ExcelApp.Range(StrCell, EndCell).Value = column_list\n",
    "    \n",
    "    # Make sure to initalize the next section.\n",
    "    section_init += 1\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
